package cn.itcast.mq.listener;

import cn.itcast.mq.config.CommonConfig;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class SpringRabbitListener {

    @RabbitListener(queues = CommonConfig.DIRECT_QUEUE)
    public void listenMessage(String msg) {
        System.out.println("消费者接收到simple.queue的消息：【" + msg + "】");
        int i = 1/0;
        System.out.println("消息处理成功");
    }

    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "error.queue"),
                            exchange = @Exchange(name = "error.exchange"),
                            key = "error.key"))
    public void listenEvent(String msg){
        System.out.println("失败重置次数耗尽后，被投递过来的消息：" + msg);
    }
}
